//
// Created by zing on 3/31/2020.
//

#include <sys/stat.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

int main() {
    //int stat(const char *pathname, struct stat *statbuf);
    struct stat st;
    int ret = stat("text.txt", &st);
    if (ret == -1) {
        perror("stat");
        return EXIT_FAILURE;
    }
    printf("st_dev:%ld\n", st.st_dev);
    printf("st_ino:%ld\n", st.st_ino);
    printf("st_nlink:%ld\n", st.st_nlink);
    printf("st_uid:%u\n", st.st_uid);
    printf("st_gid:%u\n", st.st_gid);
    printf("st_size:%ld\n", st.st_size);
    printf("st_blksize:%ld\n", st.st_blksize);
    printf("st_blocks:%ld\n", st.st_blocks);
    printf("st_mode:%d\n", st.st_mode);

    printf("st.st_atim:%s", ctime((const time_t *) &st.st_atim));
    printf("st.st_ctim:%s", ctime((const time_t *) &st.st_ctim));
    printf("st.st_mtim:%s", ctime((const time_t *) &st.st_mtim));

    printf("%d\n",(st.st_mode & S_IREAD) == S_IREAD);
    printf("%d\n",(st.st_mode & S_IEXEC) == S_IEXEC);
    printf("%d\n",(st.st_mode & S_IWRITE) == S_IWRITE);
    return EXIT_SUCCESS;
}